const Router = require('koa-router');

const {
  Auth
} = require('../../middlewares/auth.js');
const { likeValidator } = require('../../validators/validators.js');
const { Favor } = require('../../models/favor.js');

const { HttpSuccess } = require('../../core/httpError.js');
const router = new Router({
  prefix: '/v1/like'
});

router.post('/', new Auth().m, async (ctx, next) => {
  // ctx.body = JSON.stringify(ctx);
  const v = await new likeValidator().validate(ctx);
  const result = await Favor.like(v.get('body.art_id'), v.get('body.type'), ctx.auth.uid);

  ctx.body = await new HttpSuccess();
})

router.post('/cancel', new Auth().m, async (ctx, next) => {
  const v = await new likeValidator().validate(ctx);
  await Favor.dislike(v.get('body.art_id'), v.get('body.type'), ctx.auth.uid);
  // await new HttpSuccess();
})

module.exports = router;